layui.define(["table", "element"], function (exports) {
  var $ = layui.$,
    table = layui.table,
    element = layui.element;
  var technicalCategory =
    layui.sessionData("technicalCategory").key == undefined
      ? "0"
      : layui.sessionData("technicalCategory").key;
  var status =
    layui.sessionData("status").key == undefined
      ? "3"
      : layui.sessionData("status").key;

  element.tabChange("technicalRevieAgenda", technicalCategory);
  element.tabChange(`technicalRevieTab${technicalCategory}`, status);
  initPageTechnical(technicalCategory, status);

  element.on("tab(technicalRevieAgenda)", function (data) {
    technicalCategory = $(this).attr("lay-id");
    initPageTechnical(technicalCategory, status);
    layui.sessionData("agenda", {
      key: technicalCategory,
    });
  });
  // 待办和已办的切换事件调用
  function initPageTechnical(agenda, status) {
    let tabName = "technicalRevieTab" + agenda;
    if (agenda == "0") {
      switch (status) {
        case "1":
          position = `#guardianshipProgram01`;
          toolbarOperatee = `#guardianshipOpera01`;
          OperateeWidth = 350;
          hidecolumn = false;
          element.tabChange(`technicalRevieTab0`, "1");
          break;
        case "2":
          position = `#technicalReConsultation02`;
          toolbarOperatee = `#technicalReConsultationOprea02`;
          OperateeWidth = 525;
          hidecolumn = false;
          element.tabChange(`technicalRevieTab0`, "2");
          break;
        case "3":
          element.tabChange(`technicalRevieTab0`, "3");
          position = `#technicalReview03`;
          toolbarOperatee = `#technicalReviewOprea03`;
          OperateeWidth = 525;
          hidecolumn = false;
          break;
        case "4":
          position = `#protectionScheme04`;
          toolbarOperatee = `#protectionSchemeOprea04`;
          OperateeWidth = 260;
          hidecolumn = true;
          element.tabChange(`technicalRevieTab0`, "4");
          break;
        case "5":
          position = `#combinedTransformation05`;
          toolbarOperatee = `#combinedTransformationOpra05`;
          OperateeWidth = 320;
          hidecolumn = true;
          element.tabChange(`technicalRevieTab0`, "5");
          break;
      }
    } else {
      switch (status) {
        case "1":
          position = `#guardianshipProgram11`;
          OperateeWidth = 350;
          hidecolumn = false;
          toolbarOperatee = "#selectTypeOpea1";
          element.tabChange(`technicalRevieTab1`, "1");
          break;
        case "2":
          position = `#technicalReConsultation12`;
          OperateeWidth = 525;
          hidecolumn = false;
          toolbarOperatee = "#selectTypeOpea2";
          element.tabChange(`technicalRevieTab1`, "2");

          break;
        case "3":
          position = `#technicalReview13`;
          OperateeWidth = 525;
          hidecolumn = true;
          toolbarOperatee = "#selectTypeOpea3";
          element.tabChange(`technicalRevieTab1`, "3");

          break;
        case "4":
          position = `#protectionScheme14`;
          OperateeWidth = 260;
          hidecolumn = true;
          toolbarOperatee = "#selectTypeOpea4";
          element.tabChange(`technicalRevieTab1`, "4");

          break;
        case "5":
          position = `#combinedTransformation15`;
          OperateeWidth = 320;
          hidecolumn = true;
          toolbarOperatee = "#selectTypeOpea5";
          element.tabChange(`technicalRevieTab1`, "5");

          break;
      }
    }
    getList(position, status, toolbarOperatee, OperateeWidth, hidecolumn);

    element.tabChange(`${tabName}${status}`, status);
    // 数字展示
    commissionStatistics(technicalCategory);
    function commissionStatistics(technicalCategory) {
      $.ajax({
        type: "POST",
        async: false, //异步执行
        url: base_url + "/technicalAuditOpinion/commissionStatistics",
        headers: {
          Accept: "application/json; charset=utf-8",
          Authorization: layui.sessionData("userToken").key,
        },
        contentType: "application/json",
        data: JSON.stringify({ category: technicalCategory }),
        success: function (data) {
          if (data.code == 200) {
            var data = data.data;
            $("#reviewBacklogSum").html(data.reviewBacklogSum);
            $("#reviewDonelogSum").html(data.haveDoneSum);
            $(".reviewLicensing").html(data.reviewLicensing);
            $(".protectionPlan").html(data.protectionPlan);
            //监护大纲
            $(".TheOutlineCount").html(data.TheOutlineCount);
            //征询类
            $(".reviewConsult").html(data.reviewConsult);
          }
        },
      });
    }

    // getList("#technicalReview", "", "#technicalReviewOprea", 530, true);
    // 二级tab切换事件
    element.on("tab(" + tabName + ")", function (data) {
      layui.sessionData("status", {
        key: "key",
        value: $(this).attr("data-status"),
      });
      var status = layui.sessionData("status").key;
      if (agenda == "0") {
        switch (status) {
          case "1":
            toolbarOperatee = `#guardianshipOpera01`;
            OperateeWidth = 350;
            hidecolumn = false;
            element.tabChange(`technicalRevieTab0`, "1");
            break;
          case "2":
            toolbarOperatee = `#technicalReConsultationOprea02`;
            OperateeWidth = 525;
            hidecolumn = false;
            element.tabChange(`technicalRevieTab0`, "2");
            break;
          case "3":
            toolbarOperatee = `#technicalReviewOprea03`;
            OperateeWidth = 525;
            hidecolumn = false;
            element.tabChange(`technicalRevieTab0`, "3");
            break;
          case "4":
            toolbarOperatee = `#protectionSchemeOprea04`;
            OperateeWidth = 260;
            hidecolumn = true;
            element.tabChange(`technicalRevieTab0`, "4");

            break;
          case "5":
            toolbarOperatee = `#combinedTransformationOpra05`;
            OperateeWidth = 320;
            hidecolumn = true;
            element.tabChange(`technicalRevieTab0`, "5");

            break;
        }
      } else {
        switch (status) {
          case "1":
            OperateeWidth = 350;
            hidecolumn = false;
            toolbarOperatee = "#selectTypeOpea1";
            element.tabChange(`technicalRevieTab1`, "1");

            break;
          case "2":
            OperateeWidth = 525;
            hidecolumn = false;
            toolbarOperatee = "#selectTypeOpea2";
            element.tabChange(`technicalRevieTab1`, "2");

            break;
          case "3":
            OperateeWidth = 525;
            hidecolumn = true;
            toolbarOperatee = "#selectTypeOpea3";
            element.tabChange(`technicalRevieTab1`, "3");

            break;
          case "4":
            OperateeWidth = 260;
            hidecolumn = true;
            toolbarOperatee = "#selectTypeOpea4";
            element.tabChange(`technicalRevieTab1`, "4");

            break;
          case "5":
            OperateeWidth = 320;
            hidecolumn = true;
            toolbarOperatee = "#selectTypeOpea5";
            element.tabChange(`technicalRevieTab1`, "5");
            break;
        }
      }
      getList(position, status, toolbarOperatee, OperateeWidth, hidecolumn);
    });
    function getList(
      position,
      status,
      toolbarOperatee,
      OperateeWidth,
      hidecolumn
    ) {
      table.render({
        elem: position,
        skin: "nob", // 无边框风格
        height: "full-220",
        url: base_url + "/report/selectIssueProjectList", //模拟接口
        headers: {
          Accept: "application/json; charset=utf-8",
          Authorization: layui.sessionData("userToken").key,
        },
        method: "post",
        contentType: "application/json",
        parseData: function (res) {
          return {
            code: 0,
            count: res.data.projectList.total,
            data: res.data.projectList.list,
            msg: res.data.message,
          };
        },
        cols: [
          [
            { field: "no", title: "编号", align: "center", width: 130 },
            {
              field: "projectName",
              title: "工程名称",
              align: "center",
              width: 400,
              event: "projectName",
              templet: function (item) {
                return (
                  "<div title=" +
                  item.projectName +
                  " class='whiteSpace'>" +
                  item.projectName +
                  "</div>"
                );
              },
            },
            {
              field: "flowStatus",
              title: "状态",
              align: "center",
              templet: function (item) {
                return (
                  "<div title=" +
                  item.flowStatus +
                  " class='whiteSpace'>" +
                  item.flowStatus +
                  "</div>"
                );
              },
            },
            {
              field: "reviewStatus",
              title: "待办描述",
              align: "center",
              width: 260,
              hide: hidecolumn,
              // hide: hidecolumn,
              // templet: "#agentDescription",
            },
            {
              field: "insertDate",
              title: "创建时间",
              width: 210,
              align: "center",
            },
            {
              field: "insertDate",
              title: "处理时间",
              width: 210,
              align: "center",
              hide: !hidecolumn,
            },
            {
              title: "操作",
              width: OperateeWidth,
              align: "center",
              // fixed: "right",
              toolbar: toolbarOperatee,
            },
          ],
        ],
        page: true,
        limit: 5,
        limits: [5, 10, 15, 20, 25, 30],
        text: { none: "无数据" },
        where: { selectType: status, agenda },
        done: function (res, curr, count) {
          // 表格渲染完成之后的回调
          var that = this.elem.next();
          res.data.forEach(function (item, index) {
            //console.log(item.empName);item表示每列显示的数据
            if (index % 2 == 0) {
              var tr = that
                .find(".layui-table-box tbody tr[data-index='" + index + "']")
                .css("background-color", "transparent");
            } else {
              var tr = that
                .find(".layui-table-box tbody tr[data-index='" + index + "']")
                .css("background", "#EDF2FB");
            }
          });
        },
      });
    }
  }
  exports("contlist", {});
});
